#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
class Solution0 {
public:
    int commonFactors(int a, int b) {
        vector<int>ans;
        int res=0;
        for(int i=2;i<=a;i++)
        {
            if(a%i==0)ans.push_back(i);
        }
        for(int i=0;i<ans.size();i++)
        {
            if(b%ans[i]==0)res++;
        }   
        return res+1;
    }
};
class Solution {
public:

    int gcd(int a,int b)
    {
        int c=1;
        while(c)
        {
            c=a%b;
            a=b;
            b=c;
        }
        return a;
    }
    int commonFactors(int a, int b) {
        int d=gcd(a, b);
        int ans=0;
        for(int i=1;i<=d/i;i++)
        {
            if(d%i==0)
            {
                ans++;
                if(i*i!=d)ans++;
            }
        }
        return ans;
    }
};